#ifndef MOUSEUI_H
#define MOUSEUI_H

#include <QObject>
#include <QWidget>
#include <QFrame>
#include <QLabel>
#include <QVBoxLayout>
#include <QSpacerItem>
#include <QRadioButton>
#include <QSlider>
#include <QByteArray>
#include <QGSettings/QGSettings>
#include <QVariant>
#include <QApplication>
#include <QButtonGroup>
#include <QDebug>
#include <QToolButton>
#include "shell/interface.h"

#include "interface/common.h"

#include "widgets/Label/titlelabel.h"
#include "widgets/Uslider/uslider.h"
#include "widgets/SettingWidget/switchwidget.h"
#include "widgets/SettingWidget/sliderwidget.h"
#include "widgets/SettingWidget/radiobuttonwidget.h"
#include "widgets/SettingWidget/settinggroup.h"

#include "kslider.h"
#include "kswitchbutton.h"
using namespace kdk;

const QByteArray kMouseSchemas = "org.ukui.peripherals-mouse";
const QString kDominantHandKey = "left-handed";
const QString kScrollDirection = "natural-scroll";
const QString kWheelSpeedKey = "wheel-speed";
const QString kDoubleClickIntervalKey = "double-click";
const QString kPointerSpeedKey = "motion-acceleration";
const QString kMouseAccelerationKey = "mouse-accel";
const QString kPointerPositionKey = "locate-pointer";
const QString kPointerSizeKey = "cursor-size";

const QByteArray kDesktopSchemas = "org.mate.interface";
const QString kBlinkCursorOnTextKey = "cursor-blink";
const QString kCursorSpeedKey = "cursor-blink-time";

const QByteArray kThemeSchemas = "org.ukui.style";


class MyLabel : public QLabel
{
    Q_OBJECT

public:
    MyLabel();
    ~MyLabel();

public:
    QGSettings * mSettings;

protected:
    void mouseDoubleClickEvent(QMouseEvent *event);
};

class MouseUI : public QWidget, CommonInterface
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "org.ukcc.CommonInterface")
    Q_INTERFACES(CommonInterface)

public:
    MouseUI();
    ~MouseUI() Q_DECL_OVERRIDE;

    QString plugini18nName() Q_DECL_OVERRIDE;
    int pluginTypes() Q_DECL_OVERRIDE;
    QWidget *pluginUi() Q_DECL_OVERRIDE;
    const QString name() const  Q_DECL_OVERRIDE;
    bool isShowOnHomePage() const Q_DECL_OVERRIDE;
    QIcon icon() const Q_DECL_OVERRIDE;
    bool isEnable() const Q_DECL_OVERRIDE;

    void settingForIntel();
private:
    QWidget *pluginWidget;

    int pluginType;
    QString pluginName;

    bool mFirstLoad;

private:
    RadioButtonWidget *mDominantHandWidget;         // 惯用手
    RadioButtonWidget *mScrollDirectionWdiget;      // 滚动方向
    SliderWidget *mWheelSpeedWidget;           // 滚轮速度
    SliderWidget *mDoubleClickIntervalWidget;  // 双击间隔时长
    SliderWidget *mPointerSpeedWidget;         // 指针速度
    SwitchWidget *mMouseAccelerationWidget;    // 鼠标加速
    SwitchWidget *mPointerPositionWidget;      // 按 ctrl 键时显示指针位置
    RadioButtonWidget *mPointerSizeWidet;          // 指针大小
    SwitchWidget *mBlinkingCursorOnTextWidget; // 文本区域闪烁光标
    SliderWidget *mCursorSpeedWidget;          // 光标速度

    TitleLabel *mMouseTitleLabel;
    TitleLabel *mPointerTitleLabel;
    TitleLabel *mCursorTitleLabel;

    QRadioButton *mDominantHandLeftRadio;
    QRadioButton *mDominantHandRightRadio;
    QRadioButton *mScrollDirectionForwardRadio;
    QRadioButton *mScrollDirectionReverseRadio;
    QRadioButton *mPointerSizeSmallRadio;
    QRadioButton *mPointerSizeMediumRadio;
    QRadioButton *mPointerSizeLargeRadio;

    QVBoxLayout *mVlayout;

    QGSettings *mMouseGsetting;
    QGSettings *mDesktopGsetting;
    QGSettings *mThemeSettings;

private:
    void initUI(QWidget *widget);
    void setDominantHandFrame();
    void setScrollDirectionFrame();
    void setWheelSpeedFrame();
    void setDoubleClickFrame();
    void setPointerSpeedFrame();
    void setMouseAccelerationFrame();
    void setPointerPositionFrame();
    void setPointerSizeFrame();
    void setBlinkCursorFrame();
    void setCursorSpeedFrame();
    void initConnection();
    void gsettingConnection();

    void initEnableStatus();

    bool eventFilter(QObject *watched, QEvent *event);

public slots:
    void dominantHandSlot(int id);
    void scrollDirectionSlot(int id);
    void wheelSpeedSlot();
    void doubleClickIntervalSlot();
    void pointerSpeedSlot(int value);
    void mouseAccelerationSlot(bool checked);
    void pointerPositionSlot(bool checked);
    void pointerSizeSlot(int id);
    void blinkCursorOnTextSlot(bool checked);
    void cursorSpeedSlot();

};
#endif // MOUSEUI_H
